home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 November / PCWNOV07.iso / Software / Freeware / NSIS 2.29 / nsis-2.29-setup.exe / Examples / Plugin / exdll.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-06-13  |  3.1 KB  |  129 lines

  1. #ifndef _EXDLL_H_
  2. #define _EXDLL_H_
  3.  
  4. #include <windows.h>
  5.  
  6. #if defined(__GNUC__)
  7. #define UNUSED __attribute__((unused))
  8. #else
  9. #define UNUSED
  10. #endif
  11.  
  12. // only include this file from one place in your DLL.
  13. // (it is all static, if you use it in two places it will fail)
  14.  
  15. #define EXDLL_INIT()           {  \
  16.         g_stringsize=string_size; \
  17.         g_stacktop=stacktop;      \
  18.         g_variables=variables; }
  19.  
  20. // For page showing plug-ins
  21. #define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8)
  22. #define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd)
  23. #define NOTIFY_BYE_BYE 'x'
  24.  
  25. typedef struct _stack_t {
  26.   struct _stack_t *next;
  27.   char text[1]; // this should be the length of string_size
  28. } stack_t;
  29.  
  30.  
  31. static unsigned int g_stringsize;
  32. static stack_t **g_stacktop;
  33. static char *g_variables;
  34.  
  35. static int __stdcall popstring(char *str) UNUSED; // 0 on success, 1 on empty stack
  36. static void __stdcall pushstring(const char *str) UNUSED;
  37. static char * __stdcall getuservariable(const int varnum) UNUSED;
  38. static void __stdcall setuservariable(const int varnum, const char *var) UNUSED;
  39.  
  40. enum
  41. {
  42. INST_0,         // $0
  43. INST_1,         // $1
  44. INST_2,         // $2
  45. INST_3,         // $3
  46. INST_4,         // $4
  47. INST_5,         // $5
  48. INST_6,         // $6
  49. INST_7,         // $7
  50. INST_8,         // $8
  51. INST_9,         // $9
  52. INST_R0,        // $R0
  53. INST_R1,        // $R1
  54. INST_R2,        // $R2
  55. INST_R3,        // $R3
  56. INST_R4,        // $R4
  57. INST_R5,        // $R5
  58. INST_R6,        // $R6
  59. INST_R7,        // $R7
  60. INST_R8,        // $R8
  61. INST_R9,        // $R9
  62. INST_CMDLINE,   // $CMDLINE
  63. INST_INSTDIR,   // $INSTDIR
  64. INST_OUTDIR,    // $OUTDIR
  65. INST_EXEDIR,    // $EXEDIR
  66. INST_LANG,      // $LANGUAGE
  67. __INST_LAST
  68. };
  69.  
  70. typedef struct {
  71.   int autoclose;
  72.   int all_user_var;
  73.   int exec_error;
  74.   int abort;
  75.   int exec_reboot;
  76.   int reboot_called;
  77.   int XXX_cur_insttype; // deprecated
  78.   int XXX_insttype_changed; // deprecated
  79.   int silent;
  80.   int instdir_error;
  81.   int rtl;
  82.   int errlvl;
  83.   int alter_reg_view;
  84. } exec_flags_type;
  85.  
  86. typedef struct {
  87.   exec_flags_type *exec_flags;
  88.   int (__stdcall *ExecuteCodeSegment)(int, HWND);
  89.   void (__stdcall *validate_filename)(char *);
  90. } extra_parameters;
  91.  
  92. // utility functions (not required but often useful)
  93. static int __stdcall popstring(char *str)
  94. {
  95.   stack_t *th;
  96.   if (!g_stacktop || !*g_stacktop) return 1;
  97.   th=(*g_stacktop);
  98.   lstrcpyA(str,th->text);
  99.   *g_stacktop = th->next;
  100.   GlobalFree((HGLOBAL)th);
  101.   return 0;
  102. }
  103.  
  104. static void __stdcall pushstring(const char *str)
  105. {
  106.   stack_t *th;
  107.   if (!g_stacktop) return;
  108.   th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
  109.   lstrcpynA(th->text,str,g_stringsize);
  110.   th->next=*g_stacktop;
  111.   *g_stacktop=th;
  112. }
  113.  
  114. static char * __stdcall getuservariable(const int varnum)
  115. {
  116.   if (varnum < 0 || varnum >= __INST_LAST) return NULL;
  117.   return g_variables+varnum*g_stringsize;
  118. }
  119.  
  120. static void __stdcall setuservariable(const int varnum, const char *var)
  121. {
  122.     if (var != NULL && varnum >= 0 && varnum < __INST_LAST) 
  123.         lstrcpyA(g_variables + varnum*g_stringsize, var);
  124. }
  125.  
  126.  
  127.  
  128. #endif//_EXDLL_H_
  129.